<?php
declare(strict_types=1);

namespace LowCode;

use BadMethodCallException;
use Closure;
use LowCode\Support\JsBind;
use LowCode\Support\JsExp;
use LowCode\UI\Node;

/**
 * @method static Naive make(string $name = null, array $props = []) 创建节点
 * @method static Naive\Alert affix(mixed $children = null) 创建NAffix节点
 * @method static Naive\Alert alert(mixed $children = null) 创建NAlert节点
 * @method static Naive\Anchor anchor(array $children = []) 创建NAnchor节点
 * @method static Naive\AnchorLink anchorLink(array $children = []) 创建NAnchorLink节点
 * @method static Naive\Avatar avatar(string|JsExp $src = "", mixed $children = null) 创建NAvatar节点
 * @method static Naive\AvatarGroup avatarGroup(array|JsExp $options, mixed $children = null) 创建NAvatar节点
 * @method static Naive\Badge badge(mixed $children = null) 创建NBadge节点
 * @method static Naive\Blockquote blockquote(mixed $children = null) 创建NBlockquote节点
 * @method static Naive\Button button(mixed $children = null) 按钮组件
 * @method static Naive\ButtonGroup buttonGroup(mixed $children = null) 按钮组组件
 * @method static Naive\Card card(string|JsExp|Node $title = null, mixed $children = null) 创建NCard节点
 * @method static Naive\Carousel carousel(array $images = []) 创建NCarousel节点
 * @method static Naive\Checkbox checkbox() 创建NCheckbox节点
 * @method static Naive\Collapse Collapse(mixed $children = null) 创建NCollapse节点
 * @method static Naive\CollapseItem CollapseItem(string|JsExp $title = null, mixed $children = null) 创建NCollapseItem节点
 * @method static Naive\CollapseTransition CollapseTransition(mixed $children = null) 创建NCollapseTransition节点
 * @method static Naive\ColorPicker colorPicker() 创建NColorPicker节点
 * @method static Naive\DatePicker datePicker(string|JsExp $type = 'date') 创建NDatePicker节点
 * @method static Naive\Divider divider(mixed $children = null) 创建NColorPicker节点
 * @method static Naive\Dropdown dropdown(array $options = [], mixed $children = null) 创建NColorPicker节点
 * @method static Naive\El el(mixed $children = null, string|JsExp $tag = 'div') 创建NEl节点
 * @method static Naive\Ellipsis ellipsis(mixed $children = null) 创建NEllipsis节点
 * @method static Naive\Flex flex(mixed $children = null) 创建NFlex节点
 * @method static Naive\FloatButton floatButton(mixed $children = null) 创建NFloatButton节点
 * @method static Naive\FloatButtonGroup floatButtonGroup(mixed $children = null) 创建NFloatButtonGroup节点
 * @method static Naive\GradientText gradientText(mixed $children = null) 创建NGradientText节点
 * @method static Naive\Grid grid(int|string $cols = 24, int|string $xGap = 0, int|string $yGap = 1, mixed $children = null) 创建NGrid节点
 * @method static Naive\GridItem gridItem(mixed $children = null, int|null $span = null, int|null $offset = null) 创建NGridItem节点
 * @method static Naive\Icon icon(mixed $children = null) 创建NIcon节点
 * @method static Naive\Image image(string|JsExp $src = null) 创建NImage节点
 * @method static Naive\ImageGroup imageGroup(mixed $children = null) 创建NImageGroup节点
 * @method static Naive\InfiniteScroll infiniteScroll(mixed $children = null) 无限滚动组件
 * @method static Naive\Input input(string $type = 'text', mixed $value = null) 创建NInput节点
 * @method static Naive\Link link(mixed $children = null) 创建NButton a link节点
 * @method static Naive\Menu menu(array|JsExp $options = null) 创建NMenu节点
 * @method static Naive\NEmpty empty(string|JsExp $description = null, mixed $children = null) 创建NEmpty节点
 * @method static Naive\NList list(mixed $children = null) 创建NList节点
 * @method static Naive\NListItem listItem(mixed $children = null) 创建NListItem节点
 * @method static Naive\NSwitch switch(string|int|bool|JsExp $value = null) 创建NSwitch节点
 * @method static Naive\NumberAnimation numberAnimation(int|JsExp $from = 0, int|JsExp $to = null) 创建NNumberAnimation节点
 * @method static Naive\P p(mixed $children = null) 创建NP节点
 * @method static Naive\PageHeader pageHeader(string|JsExp $title, string|JsExp $subtitle = "", mixed $children = null) 创建NPageHeader节点
 * @method static Naive\PopConfirm popConfirm(mixed $children = null) 创建NPopconfirm节点
 * @method static Naive\Popover popover(mixed $children = null) 创建NPopover节点
 * @method static Naive\QrCode qrCode(string $text) 创建NQrCode节点
 * @method static Naive\Radio radio(string|JsExp $name, string|JsExp $label, string|int|bool|JsExp $value = null) 创建NRadio节点
 * @method static Naive\RadioGroup radioGroup(string|JsExp $name, string|int|bool|JsExp $value = null) 创建NRadioGroup节点
 * @method static Naive\Rate rate(int|JsExp $default = null) 创建NRate节点
 * @method static Naive\Result result(string|JsExp $title = null, mixed $children = null) 创建NResult节点
 * @method static Naive\Scrollbar scrollbar(mixed $children = null) 创建NScrollbar节点
 * @method static Naive\Skeleton skeleton(string|int|JsExp $width = null, string|int|JsExp $height = null, string|JsExp $size = 'medium') 创建NSkeleton节点
 * @method static Naive\Space space(mixed $children = null) 创建NSpace节点
 * @method static Naive\Spin spin(mixed $children = null) 创建NSpin节点
 * @method static Naive\Statistic statistic(string|int|JsExp $value = null) 创建NStatistic节点
 * @method static Naive\Steps steps(mixed $children = null) 创建NSteps节点
 * @method static Naive\Step step(string|JsExp|Node $title, mixed $children = null) 创建NStep节点
 * @method static Naive\Tab tab(string|int|JsExp $name = null) 创建NTab节点
 * @method static Naive\Tabs tabs(mixed $children = null) 创建NTabs节点
 * @method static Naive\TabPane tabPane(string|int|JsExp $name = null, string|JsBind $tab = null) 创建NTabPane节点
 * @method static Naive\Tag tag(mixed $children = null) 创建NTag节点
 * @method static Naive\Text text(mixed $children = null) 创建NText节点
 * @method static Naive\Thing thing(mixed $children = null) 创建NThing节点
 * @method static Naive\TimePicker timePicker() 创建NTimePicker节点
 * @method static Naive\Title title(mixed $children = null, int $level = 1) 创建NTitle节点
 * @method static Naive\Tooltip tooltip(mixed $children = null) 创建NTooltip节点
 * @method static Naive\Tree tree(array|JsExp $data = []) 创建NTree节点
 */
class Naive extends Node
{
    protected string $prefix = "N";

    public function __construct(string $name = null, array $props = [])
    {
        $name = $name?:class_basename($this);
        if (!str_starts_with($name,"N")){
            $name = $this->prefix.($name);
        }
        parent::__construct($name, $props);
    }


    /**
     * Dynamically handle calls to the class.
     *
     * @param string $method
     * @param array $parameters
     * @return mixed
     *
     * @throws BadMethodCallException
     */
    public static function __callStatic(string $method, array $parameters)
    {
        if (! static::hasMacro($method)) {
            if (in_array($method,["list",'empty','listItem','switch'])){
                $className = "\\LowCode\\Naive\\N".ucfirst($method);
            }else{
                $className = "\\LowCode\\Naive\\".ucfirst($method);
            }
            if (class_exists($className)){
                return $className::make(...$parameters);
            }
            throw new BadMethodCallException(sprintf(
                'Method %s::%s does not exist.', static::class, $method
            ));
        }

        $macro = static::$macros[$method];

        if ($macro instanceof Closure) {
            $macro = $macro->bindTo(null, static::class);
        }

        return $macro(...$parameters);
    }
}
